package com.nicole.reqresp;

import com.nicole.reqresp.filters.RequestFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * @author xiaoying
 */
@Configuration
@EnableConfigurationProperties({ReqRespProperties.class})
@ConditionalOnProperty(
        prefix = "spring.nicole.req.resp",
        name = {"enabled"},
        havingValue = "true",
        matchIfMissing = true
)
public class ReqRespAutoConfiguration {

    @Bean
    @ConditionalOnClass(Filter.class)
    public Filter requestFilter(ReqRespProperties properties){
        return new RequestFilter(properties);
    }
}
